import db from "../models/index.js";
let groupAnnounce = db.group_announce;
let groupAnnounceDao = {};
//获取群的公告列表
groupAnnounceDao.getGroupAnnounceList = (_group_account) => {
    return groupAnnounce.findAndCountAll({
        where: {
            _group_account
        },
        raw: true,
    });
};
//添加群公告
groupAnnounceDao.addGroupAnnounce = (_group_account, _timestamp, _announce, _session_id, t) => {
    if(!t) {
        return groupAnnounce.create({_group_account, _timestamp, _announce, _session_id});
    }
    return groupAnnounce.create({_group_account, _timestamp, _announce, _session_id}, {transaction:t});
};
//更新群公告
groupAnnounceDao.updateGroupAnnounce = (_group_account, _timestamp, _announce, _session_id, t) => {
    if(!t) {
        return groupAnnounce.update({_timestamp, _announce}, {where:{_group_account}});
    }
    return groupAnnounce.update({_timestamp, _announce}, {where:{_group_account}, transaction:t});
};
//删除群公告
groupAnnounceDao.deleteGroupAnnounce = (_group_account, _timestamp, _session_id, t) => {
    if(!t) {
        return groupAnnounce.destroy({where:{_group_account, _timestamp}});
    }
    return groupAnnounce.destroy({where:{_group_account, _timestamp}}, {transaction:t});
};
//删除同一sessionid 删除所有群公告
groupAnnounceDao.deleteGroupAnnounceList = (_session_id, t) => {
    if(!t) {
        return groupAnnounce.destroy({where:{_session_id}});
    }
    return groupAnnounce.destroy({where:{_session_id}}, {transaction:t});
};
export default groupAnnounceDao;
